<template>
  <div>
    <div class="his-hot" v-if="isShowHistory">
      <div class="hd">
        <h4>历史记录</h4>
        <van-icon name="delete-o" @click="clearFn" />
      </div>
      <div class="bd">
        <van-tag
          type="default"
          plain
          v-for="(item, index) in historyListData"
          :key="index"
          @click="tagClick(item)"
          >{{ item }}</van-tag
        >
      </div>
    </div>

    <div class="his-hot">
      <div class="hd">
        <h4>热门搜索</h4>
        <!-- <van-icon name="delete-o" /> -->
      </div>
      <div class="bd">
        <van-tag
          type="danger"
          plain
          v-for="(item, index) in hotKeywordListData"
          :key="index"
          @click="tagClick(item.keyword)"
          >{{ item.keyword }}</van-tag
        >
      </div>
    </div>
  </div>
</template>

<script>
import { Clearhistory } from "@/request/api.js";
export default {
  name: "HistoryHot",
  data() {
    return {
      isShowHistory: true,
    };
  },
  props: ["historyListData", "hotKeywordListData"],
  methods: {
    tagClick(val) {
      this.$emit("tagClick", val);
    },
    clearFn() {
      Clearhistory().then((res) => {
        if (res.errno == 0) {
          console.log(res);
          // Toast.success("删除浏览记录成功");
          this.$toast.success("删除浏览记录成功");
          setTimeout(() => {
            this.isShowHistory = false;
          }, 1000);
        }
      });
    },
  },
};
</script>

<style scoped>
.his-hot {
  background-color: #fff;
  padding: 0.1rem;
  margin-bottom: 0.3rem;
}
.hd {
  display: flex;
  justify-content: space-between;
  font-size: 0.2rem;
  margin-bottom: 0.05rem;
}

.van-icon {
  font-size: 0.25rem;
}

.van-tag {
  margin-right: 0.05rem;
  margin-top: 0.05rem;
}
</style>